export const Base64 = {
  // 编码方法
  encode: function (str) {
    return btoa(
      encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) =>
        String.fromCharCode('0x' + p1)
      )
    )
  },

  // 解码方法
  decode: function (base64) {
    const str = atob(base64)
    return decodeURIComponent(
      str
        .split('')
        .map((c) => '%' + c.charCodeAt(0).toString(16).padStart(2, '0'))
        .join('')
    )
  }
}
